package com.lijiankun24.shadowlayoutexample.slice;

import com.lijiankun24.shadowlayoutexample.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

/**
 * 主页
 *
 * @author rpf
 * @since 2021-03-08
 */
public class MainAbilitySlice extends AbilitySlice {
    private HiLogLabel logLabel = new HiLogLabel(HiLog.LOG_APP, 0x00001, "ShadowLayout");

    /**
     * onStart
     *
     * @param intent
     */
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        HiLog.info(logLabel, "onStart");
        initComponent();
    }

    private void initComponent() {
        Text show = (Text) findComponentById(ResourceTable.Id_text_show);
        Text dynamicChange = (Text) findComponentById(ResourceTable.Id_text_dynamic_change);
        Text list = (Text) findComponentById(ResourceTable.Id_text_list);

        Intent intent = new Intent();

        show.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                present(new ShowAbilitySlice(), intent);
            }
        });

        dynamicChange.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                present(new DynamicChangeAbilitySlice(), intent);
            }
        });

        list.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                present(new ListAbilitySlice(), intent);
            }
        });
    }

    /**
     * onActive
     */
    @Override
    public void onActive() {
        super.onActive();
        HiLog.info(logLabel, "onActive");
    }

    /**
     * onForeground
     *
     * @param intent
     */
    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
        HiLog.info(logLabel, "onForeground");
    }

    /**
     * onBackground
     */
    @Override
    protected void onBackground() {
        super.onBackground();
        HiLog.info(logLabel, "onBackground");
    }

    /**
     * onStop
     */
    @Override
    protected void onStop() {
        super.onStop();
        HiLog.info(logLabel, "onStop");
    }

    /**
     * onInactive
     */
    @Override
    protected void onInactive() {
        super.onInactive();
        HiLog.info(logLabel, "onInactive");
    }
}
